package com.chaofan.authsso.client.util;

import com.chaofan.authsso.client.common.Constant;

/**
 * 接口地址工具类
 * Author: Chaofan
 * Date: 2020/6/4 16:34
 * email: chaofan2685@qq.com
 */
public class SsoUrlUtil {

    public static String getCheckCoreServiceUrl(String host){
        return urlToNormalize(host)+ Constant.AUTH_SSO_SERVICE_TEST_URL;
    }

    public static String getLoginUrl(String host, String authCode){
        return urlToNormalize(host)+ Constant.AUTH_SSO_LOGIN_URL +authCode;
    }

    public static String getCheckTokenUrl(String host, String token){
        return urlToNormalize(host)+Constant.AUTH_SSO_CHECK_TOKEN_URL+token;
    }

    public static String getApplyTokenUrl(String host, String sessionId){
        return urlToNormalize(host)+Constant.AUTH_SSO_APPLY_TOKEN_URL+sessionId;
    }

    public static String getInvalidateTokenUrl(String host, String token){
        return urlToNormalize(host)+Constant.AUTH_SSO_INVALIDATE_TOKEN_URL+token;
    }

    /**
     * TODO 修复常见的url问题(持续完善)
     * @param host
     * @return
     */
    private static String urlToNormalize(String host){
        if (host.endsWith("/")){
            host = host.substring(0,host.length()-1);
        }
        return host;
    }

}
